# list = [1,3,4]
# #
# # print(list)
# # print(*list)

#
# class Person(object):
#
#     def __eq__(self, other):
#         return "abc"
#
#
# if __name__ == '__main__':
#
#     p1 = Person()
#     p2 = Person()
#     print(p1 == p2)

# import functools
#
#
# def get_user_data(func):
#
#     @functools.wraps(func)
#     def wrapper(*args, **kwargs):
#
#         # 装饰器的业务逻辑
#         return func(*args, **kwargs)
#
#     return wrapper
#
#
# """
# 问题：只要使用装饰器装饰函数，装饰器会改变函数的函数名称&函数的内部注释
#
# 解决方案： 1.导入import functools
#          2.@functools.wraps(func)装饰到wrapper内层装饰器函数上
# """
#
#
# @get_user_data
# def index():
#     """首页函数"""
#     return "index"
#
#
# @get_user_data
# def profile():
#     """个人中心函数"""
#     return "profile"
#
#
# if __name__ == '__main__':
#     print(index.__name__)
#     print(profile.__name__)
import random
import datetime

from info import db
from info.models import User
from manage import app


def add_test_users():
    # 用户列表
    users = []
    # 当前时间
    now = datetime.datetime.now()
    # 生成一万个用户
    for num in range(0, 10000):
        try:
            user = User()
            user.nick_name = "%011d" % num
            user.mobile = "%011d" % num
            user.password_hash = "pbkdf2:sha256:50000$SgZPAbEj$a253b9220b7a916e03bf27119d401c48ff4a1c81d7e00644e0aaf6f3a8c55829"
            # 用户活跃量        当前时间  - （0天 ~ 31天中间的随机秒数）： 2018-12-5号 ~ 2019-1-5 任意一个时间点登录
            user.last_login = now - datetime.timedelta(seconds=random.randint(0, 2678400))
            users.append(user)
            print(user.mobile)
        except Exception as e:
            print(e)
    # 手动开启应用上下文
    with app.app_context():
        # 往数据库添加用户对象
        db.session.add_all(users)
        db.session.commit()
    print("OK")


if __name__ == '__main__':
    add_test_users()